/*
 * ml20gui - The MSN Webcam Recorder
 * This source code is under the GNU Public License (GPL).
 * Written by Ramiro Polla
 * Initial release: june 3rd, 2005
 *
 * this program records MSN Webcam Video
 */

#include "ml20gui.h"

extern char folder[MAX_PATH];

//IDC_APPNAME
//MSN Webcam Recorder x.xx
//IDC_CRASH1
//MSN Webcam Recorder has crashed probably due to the following file:
//IDC_FNAME
//filename
//IDC_CRASH3
//It is recommended that you send this file to the developer, so that it can be analyzed and the problem fixed in future versions. Click on "Send File" if you wish to do so.
//IDC_CRASH4
//The file must also be deleted or quarantined to avoid the program to keep crashing.
//IDC_SEND_FILE
//Send File
//IDC_QUARANTINE
//Quarantine
//IDC_DELETE
//Delete
//IDC_NO_ACTION
//No Action

LRESULT CALLBACK CrashProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg) {
        case WM_INITDIALOG:
            {
                char appversion[MAX_PATH];
            //put me on the middle of the screen with the appropriate size
                HWND dsk = GetDesktopWindow( );
                RECT rc, rc2;
                GetWindowRect( dsk, &rc );
                GetWindowRect( hwnd, &rc2 );

                SetWindowPos( hwnd,
                    0,
                    ((rc.right-rc.left)-(rc2.right-rc2.left))>>1,
                    ((rc.bottom-rc.top)-(rc2.bottom-rc2.top))>>1,
                    0,
                    0,
                    SWP_NOSIZE );

                sprintf( appversion, "%s %s", appname, ml20dll_version( ) );
                SetWindowText( hwnd, str_crash );
                SetDlgItemText( hwnd, IDC_APPNAME, appversion );
                SetDlgItemText( hwnd, IDC_CRASH1, str_crash1 );
                SetDlgItemText( hwnd, IDC_FNAME, (char*) lParam );
                SetDlgItemText( hwnd, IDC_CRASH3, str_crash3 );
                SetDlgItemText( hwnd, IDC_CRASH4, str_crash4 );
                SetDlgItemText( hwnd, IDC_SEND_FILE, str_send_file );
                SetDlgItemText( hwnd, IDC_QUARANTINE, str_quarantine );
                SetDlgItemText( hwnd, IDC_DELETE, str_delete );
                SetDlgItemText( hwnd, IDC_NO_ACTION, str_no_action );
            }
            break;
        case WM_CLOSE:
            EndDialog( hwnd, 0 );
            break;
        case WM_COMMAND:
        {
            switch(LOWORD(wParam)) {
            case IDC_SEND_FILE:
                ShellExecute( NULL, NULL, getbrowser( ), "http://ml20rc.msnfanatic.com/sendfile.html", NULL, SW_SHOWNORMAL );
                break;
            case IDC_QUARANTINE:
                {
                    int lResult;
                    char fullname[MAX_PATH];
                    char newname[MAX_PATH];
                    char buf[MAX_PATH];

                    GetDlgItemText( hwnd, IDC_FNAME, fullname, MAX_PATH );
                    PathStripPath( fullname );
                    strcpy( newname, folder );
                    strcat( newname, "bad\\" );
                    CreateDirectory( newname, 0 );
                    strcat( newname, fullname );
                    GetDlgItemText( hwnd, IDC_FNAME, fullname, MAX_PATH );
                    lResult = MoveFile( fullname, newname );

                    sprintf( buf, str_stream__renamed, !lResult ? str__not_ : " " );

                    if( !lResult )
                        MessageBox( hwnd, buf, buf, MB_OK | MB_ICONEXCLAMATION );

                    EndDialog( hwnd, 0 );
                }
                break;
            case IDC_DELETE:
                {
                    int lResult;
                    char fullname[MAX_PATH];
                    char buf[MAX_PATH];

                    GetDlgItemText( hwnd, IDC_FNAME, fullname, MAX_PATH );
                    lResult = DeleteFile( fullname );

                    sprintf( buf, str_stream__deleted, !lResult ? str__not_ : " " );

                    if( !lResult )
                        MessageBox( hwnd, buf, buf, MB_OK | MB_ICONEXCLAMATION );

                    EndDialog( hwnd, 0 );
                }
                break;
            case IDC_NO_ACTION:
                EndDialog( hwnd, 0 );
                break;
            }
            break;
        }
        default:
            return FALSE;
    }
    return TRUE;
}
